package com.talos.ums.enums;

import com.fasterxml.jackson.annotation.JsonValue;

import java.util.Objects;

/**
 * 账号类型，身份 内勤-internal_affairs,司机-driver,其他-other
 */
public enum IdentityTypeEnum {

    INTERNAL_AFFAIRS("internal_affairs", "内勤"),
    DRIVER("driver", "司机"),
    OTHER("other", "其他");

    @JsonValue
    private final String code;
    private final String msg;

    IdentityTypeEnum(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public String getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    /**
     * 枚举类型转换，由于构造函数获取了枚举的子类enums，让遍历更加高效快捷
     *
     * @param code 数据库中存储的自定义code属性
     * @return code对应的枚举类
     */
    public static IdentityTypeEnum codeOf(String code) {
        for (IdentityTypeEnum status : IdentityTypeEnum.values()) {
            if (Objects.equals(status.getCode(), code)) {
                return status;
            }
        }
        return null;
    }

}
